package com.match.competition_apply.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.match.commonutils.Result;
import com.match.competition_apply.entity.CompetitionSignUp;
import com.match.competition_apply.entity.SignUpProgress;
import com.match.competition_apply.service.SignUpProgressService;
import com.match.competition_apply.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.security.SignedObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AdiosF
 * @since 2021-11-25
 */
@Api(tags = "查看报名进度模块")
@RestController
@RequestMapping("/competition_apply/sign-up-progress")
public class SignUpProgressController extends BaseController{

      @ApiOperation("添加进度")
      @PostMapping("/addSignUpProgress")
      public Result addSignUpProgress(@RequestBody SignUpProgress signUpProgress){
          signUpProgressService.save(signUpProgress);
          return Result.ok();
      }


      @ApiOperation("根据报名ID查找报名信息")
      @GetMapping("/getSignUpListProgress/{signUpId}")
      public Result getSignUpListProgress(@PathVariable(value = "signUpId")String signUpId){
          CompetitionSignUp competitionSignUpServiceById = competitionSignUpService.getById(signUpId);
          List<SignUpProgress> signUpProgressList = signUpProgressService.list(new QueryWrapper<SignUpProgress>().eq("signup_id",signUpId).orderByAsc("states"));
          SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy/MM/dd");
          for (SignUpProgress signUpProgress : signUpProgressList) {
              signUpProgress.setWorkName(competitionSignUpServiceById.getWorkName());
              if (!StringUtils.isEmpty(signUpProgress.getGmtModified())){
                  String transformDate=simpleDateFormat.format(signUpProgress.getGmtModified());
                  signUpProgress.setGmtModifiedTime(transformDate);
              }
          }
          return Result.ok().data("signUpProgressList",signUpProgressList);
      }
}

